package cn.tedu.toa.management.sys.mapper;

import cn.tedu.toa.management.sys.entity.SysRoles;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色 Mapper 接口
 * </p>
 *
 * @author huaqian
 * @since 2021-09-09
 */
public interface SysRolesMapper extends BaseMapper<SysRoles> {

    List<SysRoles> selectRoleList(String roleName);

    @Override
    int insert(SysRoles entity);

    int insertRoleMenus(@Param("roleId") Integer roleId,@Param("menuIds") Integer[] menuIds);


    //查询用户菜单表是否有存在
    @Select("select menu_id from sys_role_menus where role_id=#{roleId}")
    List<Integer> selectSysRoleMenusByRoleId(Integer roleId);

    //查询用户角色表是否存在
    @Select("select count(*) from sys_user_roles where role_id=#{roleId}")
    Integer selectSysUserRolesByRoleId(Integer roleId);
    //删除角色菜单表
    @Delete("delete from sys_role_menus where role_id=#{roleId}")
    Integer delSysRoleMenus(Integer roleId);
    //删除用户角色表
    @Delete("delete from sys_user_roles where role_id=#{roleId}")
    Integer delSysUserRoles(Integer roleId);
    //删除角色表
    @Delete("delete from sys_roles where id=#{roleId}")
    Integer delRole(Integer roleId);

    @Select("select count(*) from  sys_role_menus where role_id in (#{menuIds})")
    Integer selectCountRoleMenuByMenuIds(String menuIds);

    //根据角色数组 查询角色数量
    int selectRoleCount(@Param("roleIds") Integer[] roleIds);

    List<Integer> selectMenuIdsByRoleIds(@Param("roleIds") Integer[] roleIds);






}
